<?php

/**
 * This is the model class for table "my_message".
 *
 * The followings are the available columns in table 'my_message':
 * @property integer $id_my_message
 * @property integer $id_sender
 * @property string $subject
 * @property string $content
 * @property integer $id_receiver
 * @property string $date_add
 *
 * The followings are the available model relations:
 * @property Me $idSender
 */
class MyMessage extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return MyMessage the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'my_message';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_sender, content', 'required'),
			array('id_sender, id_receiver', 'numerical', 'integerOnly'=>true),
			array('subject', 'length', 'max'=>255),
			array('date_add', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_my_message, id_sender, subject, content, id_receiver, date_add', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idSender' => array(self::BELONGS_TO, 'Me', 'id_sender'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_my_message' => 'Id My Message',
			'id_sender' => 'Id Sender',
			'subject' => 'Subject',
			'content' => 'Content',
			'id_receiver' => 'Id Receiver',
			'date_add' => 'Date Add',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_my_message',$this->id_my_message);
		$criteria->compare('id_sender',$this->id_sender);
		$criteria->compare('subject',$this->subject,true);
		$criteria->compare('content',$this->content,true);
		$criteria->compare('id_receiver',$this->id_receiver);
		$criteria->compare('date_add',$this->date_add,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}